class Solution:
    def mergeNodes(self, head):
        newlist = []
        i_sum = 0
        for i, key in enumerate(head):
            i_sum += 1
            if key == 0:
                i_old = i - i_sum
                i_sum = i
                newlist.append(sum(head[i_old:i]))
                if len(newlist) > 1:
                    i_sum = 0
        return newlist[1:]


head = [0, 1, 0, 3, 0, 2, 2, 0]
aa = Solution()
bb = aa.mergeNodes(head)
print(bb)
